package com.dede.viewpagertest

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_child.*

/**
 * @author hsh
 * @date 2017/12/8 14:06.
 * @doc
 */
class ChildViewPagerFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        return inflater!!.inflate(R.layout.fragment_child, container, false)
    }

    //直接通过id操作view需要在onViewCreated执行以后
    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        view_pager.adapter = ChildAdapter(childFragmentManager)
        tab_layout.setupWithViewPager(view_pager)
    }

    inner class ChildAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {

        override fun getItem(position: Int): Fragment {
            return ChildFragment()
        }

        override fun getCount(): Int = 5

        override fun getPageTitle(position: Int): CharSequence {
            return position.toString()
        }

    }
}